/**
 * 
 */
package com.questiono;

import java.io.IOException;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.util.Log;
import com.sameer.questiono.R;


/**
 * @author sameer
 *
 */
public class Sound extends Activity {

	/**
	 * @param args
	 */
	
	
	
	private static SoundPool soundPool;
	private static HashMap soundPoolMap;

	/** Populate the SoundPool*/
	public static void initSounds(Context context) {
    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 100);
	soundPoolMap = new HashMap(3);     

	/*soundPoolMap.put( sniper, soundPool.load(context, R.raw.sniper, 1) );*/
/*	soundPoolMap.put( S2, soundPool.load(context, R.raw.s2, 2) );
	soundPoolMap.put( S3, soundPool.load(context, R.raw.s3, 3) );
*/	
	}
	
	 /** Play a given sound in the soundPool */
	 public void playSound(Context context, int soundID) {
		 
		 try{
	            boolean mStartPlaying = true;
	            MediaPlayer  mPlayer=null;
	            if (mStartPlaying==true){
	                mPlayer = new MediaPlayer();

	                
	                mPlayer = MediaPlayer.create(context, soundID); 
	                mPlayer.start();
	               
	               /* Uri uri = Uri.parse("android.resource://com.questiono/" + soundID);
	                mPlayer.setDataSource(context,uri);
	                mPlayer.prepare();
	                mPlayer.start();*/
	            } 
	            else{
	                mPlayer.release();
	                mPlayer = null;
	            }
	            mStartPlaying = !mStartPlaying;
	        }
	        catch (Exception e){
	            Log.e("error", "prepare() failed");
	        }

	 }
	
 public void playSoundLoop(Context context, int soundID) {
		 
		 try{
	            boolean mStartPlaying = true;
	            MediaPlayer  mPlayer=null;
	            if (mStartPlaying==true){
	                mPlayer = new MediaPlayer();

	                
	                mPlayer = MediaPlayer.create(context, soundID);
	                mPlayer.setLooping(true);
	                mPlayer.start();
	                
	                
	               /* Uri uri = Uri.parse("android.resource://com.questiono/" + soundID);
	                mPlayer.setDataSource(context,uri);
	                mPlayer.prepare();
	                mPlayer.start();*/
	            } 
	            else{
	                mPlayer.release();
	                mPlayer = null;
	            }
	            mStartPlaying = !mStartPlaying;
	        }
	        catch (Exception e){
	            Log.e("error", "prepare() failed");
	        }

	 }
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
